package com.zy.cat.controller.dev.v1;

import java.time.LocalDate;
import java.util.Date;
import java.util.concurrent.Callable;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zy.cat.common.annotation.CheckDevPermission;
import com.zy.cat.common.annotation.CheckingMD5;
import com.zy.cat.entity.dev.CatDevUserInfo;
import com.zy.cat.entity.dev.act.CatDailyDrawAwardeeOrder;
import com.zy.cat.entity.dev.act.CatDailyDrawDetail;
import com.zy.cat.entity.dev.act.CatDailyDrawHistory;
import com.zy.cat.entity.dev.act.CatDailyDrawResult;
import com.zy.cat.entity.dev.act.repository.CatDailyDrawAwardeeOrderRepository;
import com.zy.cat.entity.dev.act.repository.CatDailyDrawDetailRepository;
import com.zy.cat.entity.dev.act.repository.CatDailyDrawHistoryRepository;
import com.zy.cat.entity.dev.act.repository.CatDailyDrawResultRepository;
import com.zy.cat.entity.dev.act.resp.APPActDBHistoryResp;
import com.zy.cat.entity.dev.act.resp.APPActDBInfoResp;
import com.zy.cat.entity.dev.act.resp.CatDailyDrawAwardeeOrderResp;
import com.zy.cat.entity.dev.act.resp.CatDailyDrawDetailResp;
import com.zy.cat.entity.dev.act.resp.CatDailyDrawListResp;
import com.zy.cat.entity.dev.act.resp.CatDailyDrawListResp.Prize;
import com.zy.cat.entity.resp.Pages;
import com.zy.cat.entity.resp.RSPE;
import com.zy.cat.entity.resp.ResultPage;
import com.zy.cat.service.CatDevActService;
import com.zy.cat.service.CatDevService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @info
 * @author Link
 * @date 2019-11-28 18:45
 */
@Slf4j
@RestController
@RequestMapping("/v1/user/act")
@Api(value = "9catDevUser", tags = { "9趣猫活动信息开放API" }, description = "9趣猫活动信息开放接口")
public class CatDevActInfoController {

	@Autowired
	CatDevActService catDevActService;
	
	@Autowired
	CatDevService catDevService;
	
	@Autowired
	CatDailyDrawHistoryRepository dailyDrawHistoryRepository;
	
	@Autowired
	CatDailyDrawDetailRepository dailyDrawDetailRepository;
	
	@Autowired
	CatDailyDrawResultRepository dailyDrawResultRepository;
	
	@Autowired
	CatDailyDrawAwardeeOrderRepository dailyDrawAwardeeOrderRepository;

	@PostMapping("/mfc/info")
	@ApiOperation(value = "九趣猫APP获取免费抽信息", position = 1, notes = "免费抽信息，包含商品列表，个人进度", response = APPActDBInfoResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_imsi_pid_cid_imei_utoken_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_imsi_pid_cid_imei_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getCJInfo(Integer vscode, String cid, String imei, String imsi, String pid, String uuid,String utoken,
			String token) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-2, "参数错误！");
		}
		return new Callable<RSPE<APPActDBInfoResp>>() {
			@Override
			public RSPE<APPActDBInfoResp> call() throws Exception {
				APPActDBInfoResp re = catDevActService.getDbInfo(pid);
				if (re == null) {
					return new RSPE<APPActDBInfoResp>(-3, "今日抽奖次数已用完！");
				}
				return new RSPE<APPActDBInfoResp>(re);
			}
		};
	}

	@PostMapping("/mfc/start")
	@ApiOperation(value = "参与九趣猫APP免费抽", position = 2, notes = "返回参与免费抽的券ID", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "cindex", value = "免费抽期数", example = "1", dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "sid", value = "商品ID", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_cid_imsi_pid_imei_utoken_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_cid_imsi_pid_imei_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getCJStart(String uuid,Integer vscode, String cid, String imei, String imsi, String pid, String sid,
			Integer cindex, String utoken, String token) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-2, "参数错误！");
		}
		return new Callable<RSPE<Object>>() {
			@Override
			public RSPE<Object> call() throws Exception {
				return catDevActService.getDbStart(cindex, sid, pid);
			}
		};
	}

	@PostMapping("/mfc/list")
	@ApiOperation(value = "个人参与APP免费抽记录", position = 3, notes = "返回参与的抽奖记录", response = APPActDBHistoryResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "dstatus", value = "状态（10.全部、1.中奖）", example = "10", dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_cid_imsi_pid_imei_utoken_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_cid_imsi_pid_imei_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getCJList(String uuid,Integer vscode, String cid, String imei, String imsi, String pid, Integer dstatus,
			String utoken, String token, Pages pages) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-3, "参数错误！");
		}
		if (dstatus == null || dstatus != 10) {
			return new RSPE<ResultPage<APPActDBHistoryResp>>(null);
		}

		return new Callable<RSPE<ResultPage<APPActDBHistoryResp>>>() {
			@Override
			public RSPE<ResultPage<APPActDBHistoryResp>> call() throws Exception {
				return new RSPE<ResultPage<APPActDBHistoryResp>>(catDevActService.getDbList(pid, dstatus, pages));
			}
		};
	}

	@PostMapping("/mfc/rlist")
	@ApiOperation(value = "九趣猫APP免费抽中奖记录", position = 6, notes = "返回参与免费抽的中奖记录", response = APPActDBHistoryResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_cid_imsi_pid_imei_utoken_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_cid_imsi_pid_imei_utoken", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object getCJRList(String uuid,Integer vscode, String cid, String imei, String imsi, String pid, String utoken,
			String token, Pages pages) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-3, "参数错误！");
		}

		return new Callable<RSPE<ResultPage<APPActDBHistoryResp>>>() {
			@Override
			public RSPE<ResultPage<APPActDBHistoryResp>> call() throws Exception {
				return new RSPE<ResultPage<APPActDBHistoryResp>>(catDevActService.getDbRList(pid, pages));
			}
		};
	}
	
	@PostMapping("/daily/draw/info")
	@ApiOperation(value = "天天抽奖信息", position = 7, notes = "天天信息，包含商品列表，个人进度", response = CatDailyDrawListResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "客户端", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "cid", value = "渠道ID", example = "chan101", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imei", value = "手机IMEI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "imsi", value = "手机IMSI", example = "862052038380307", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_imsi_cid_imei_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_imsi_cid_imei", MD5 = "token", checkSingle = true)
	public Object getDailyDrawInfo(Integer rtype,Integer vscode, String cid, String imei, String imsi, String pid, String uuid,String token) {
		if(!StringUtils.isBlank(pid)) {
			CatDevUserInfo userInfo = catDevService.getCatDevUserInfoByPid(pid);
			if (userInfo==null) {
				return new RSPE<Object>(-3, "用户不存在！");
			}
		}
		return new Callable<RSPE<CatDailyDrawListResp>>() {
			@Override
			public RSPE<CatDailyDrawListResp> call() throws Exception {
				CatDailyDrawListResp re = catDevActService.getDailyDrawInfo(pid);
				if (re == null) {
					return new RSPE<CatDailyDrawListResp>(-3, "获取奖品信息失败！");
				}
				return new RSPE<CatDailyDrawListResp>(re);
			}
		};
	}
	
	@PostMapping("/daily/draw/list")
	@ApiOperation(value = "天天抽奖记录", position = 8, notes = "返回参与的抽奖记录", response = Prize.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "客户端", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pageNum", value = "页码", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pageSize", value = "页面大小", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "type", value = "查询中奖记录类型(0.全部记录、1.个人参与抽奖记录)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "drawStatus", value = "抽奖状态(0.未开奖、1.已开奖)", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_rtype_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_rtype", MD5 = "token", checkSingle = true)
	public Object getDailyDrawList(Integer rtype,Integer vscode, Integer pageNum, Integer pageSize,Integer type,Integer drawStatus, String pid, String uuid,String token) {

		if (type==null) {
			return new RSPE<Object>(-3, "查询类型不存在！");
		}
		if (type==1 && StringUtils.isBlank(pid)) {
			return new RSPE<Object>(-2, "用户ID不存在！");
		}
		
		if(!StringUtils.isBlank(pid)) {
			CatDevUserInfo userInfo = catDevService.getCatDevUserInfoByPid(pid);
			if (userInfo==null) {
				return new RSPE<Object>(-3, "用户不存在！");
			}
		}
		return new Callable<RSPE<ResultPage<Prize>>>() {
			@Override
			public RSPE<ResultPage<Prize>> call() throws Exception {
				ResultPage<Prize> re = catDevActService.getDailyDrawList(pid,type,drawStatus,pageNum,pageSize);
				return new RSPE<ResultPage<Prize>>(re);
			}
		};
	}

	@PostMapping("/daily/draw/detail")
	@ApiOperation(value = "天天抽奖活动详情", position = 8, notes = "返回参与的抽奖详情", response = CatDailyDrawDetailResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "客户端", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "drawId", value = "抽奖ID", example = "1111111111", dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_rtype_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_rtype", MD5 = "token", checkSingle = true)
	public Object getDailyDrawDetail(Integer rtype,Integer vscode, Integer drawId, String pid, String uuid,String token) {
		if(!StringUtils.isBlank(pid)) {
			CatDevUserInfo userInfo = catDevService.getCatDevUserInfoByPid(pid);
			if (userInfo==null) {
				return new RSPE<Object>(-3, "用户不存在！");
			}
		}
		return new Callable<RSPE<CatDailyDrawDetailResp>>() {
			@Override
			public RSPE<CatDailyDrawDetailResp> call() throws Exception {
				CatDailyDrawDetailResp re = catDevActService.getDailyDrawDetail(pid,drawId);
				if (re == null) {
					return new RSPE<CatDailyDrawDetailResp>(-3, "获取中奖详情信息失败！");
				}
				return new RSPE<CatDailyDrawDetailResp>(re);
			}
		};
	}
	
	@PostMapping("/daily/draw/increase")
	@ApiOperation(value = "提升天天抽奖幸运值", position = 9, notes = "提升天天抽奖幸运值", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "客户端", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "drawId", value = "抽奖ID", example = "1111111111", dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_pid_rtype_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_pid_rtype", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object addDailyDrawProbability(Integer rtype,String uuid,Integer vscode, Integer drawId, String pid,String utoken, String token) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-2, "参数错误！");
		}
		if (drawId==null) {
			return new RSPE<Object>(-2, "抽奖ID为空！");
		}
		CatDailyDrawDetail drawDetail = dailyDrawDetailRepository.findByPidAndDrawIdAndCreateTimeGreaterThanEqual(pid,drawId,new Date(LocalDate.now().toEpochDay()));
		//校验次数是否用完
		if (drawDetail!=null && drawDetail.getIncreaseCount()>=5) {
			return new RSPE<Object>(-3, "今日提升次数已用完！");
		}
		
		CatDailyDrawHistory drawHistory = dailyDrawHistoryRepository.findById(drawId.longValue());
		if (drawHistory==null) {
			return new RSPE<Object>(-4, "抽奖活动不存在！");
		}
		if (drawHistory.getDrawStatus()==1) {
			return new RSPE<Object>(-5, "本轮已开奖，无法进行提升！");
		}
		if (drawDetail==null && drawHistory.getDrawNum()>=drawHistory.getDrawTotal()) {
			return new RSPE<Object>(-6, "开奖人数已满，即将开奖！");
		}
		
		return new Callable<RSPE<Object>>() {
			@Override
			public RSPE<Object> call() throws Exception {
				Integer detail=catDevActService.addDailyDrawProbability(drawId, pid,drawHistory,drawDetail);;
				if (detail == null) {
					return new RSPE<Object>(0, "提升失败，请稍后重试！");
				}
				return new RSPE<Object>(detail);
			}
		};
	}
	
	@PostMapping("/daily/draw/check_add")
	@ApiOperation(value = "检查提升天天抽奖幸运值机会", position = 9, notes = "检查提升天天抽奖幸运值机会", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "drawId", value = "抽奖ID", example = "1111111111", dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_pid_rtype_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_pid_rtype", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object checkDailyDrawProbability(String uuid,Integer vscode, Integer drawId, String pid,String utoken, String token) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-2, "参数错误！");
		}
		if (drawId==null) {
			return new RSPE<Object>(-2, "抽奖ID为空！");
		}
		CatDailyDrawDetail drawDetail = dailyDrawDetailRepository.findByPidAndDrawIdAndCreateTimeGreaterThanEqual(pid,drawId,new Date(LocalDate.now().toEpochDay()));
		//校验次数是否用完
		if (drawDetail!=null && drawDetail.getIncreaseCount()>=5) {
			return new RSPE<Object>(-3, "今日提升次数已用完！");
		}
		
		CatDailyDrawHistory drawHistory = dailyDrawHistoryRepository.findById(drawId.longValue());
		if (drawHistory==null) {
			return new RSPE<Object>(-4, "抽奖活动不存在！");
		}
		if (drawHistory.getDrawStatus()==1) {
			return new RSPE<Object>(-5, "本轮已开奖，无法进行提升！");
		}
		if (drawDetail==null && drawHistory.getDrawNum()>=drawHistory.getDrawTotal()) {
			return new RSPE<Object>(-6, "开奖人数已满，请坐等开奖！");
		}
		
		return new RSPE<Object>("可提升幸运值");
	}
	

	@PostMapping("/daily/draw/receive")
	@ApiOperation(value = "天天抽奖兑奖", position =10, notes = "填写收件人信息及联系方式", response = RSPE.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "客户端", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "drawId", value = "抽奖ID", example = "1111111111", dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "recipientName", value = "收件人名称", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "recipientPhone", value = "收件人手机号", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "area", value = "省市县,已逗号分隔", example = "山东省，济南市，XX区", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "address", value = "详细地址", example = "XXXX", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_pid_rtype_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_pid_rtype", MD5 = "token", checkSingle = true)
	@CheckDevPermission
	public Object receiveDailyDrawPrize(Integer rtype,String uuid,String recipientName,String recipientPhone,String area,String address,Integer vscode, Integer drawId,
			String pid,String utoken, String token) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-2, "参数错误！");
		}
		if (drawId==null) {
			return new RSPE<Object>(-2, "抽奖ID为空！");
		}
		if (StringUtils.isBlank(recipientName)) {
			return new RSPE<Object>(-1, "收件人名称不能为空");
		}
		if (StringUtils.isBlank(recipientPhone)) {
			return new RSPE<Object>(-1, "收件人手机号不能为空");
		}
		if (StringUtils.isBlank(area)) {
			return new RSPE<Object>(-1, "收货地区不能为空");
		}
		if (area.split(",").length<3) {
			return new RSPE<Object>(-1, "收货地区参数错误");
		}
		if (StringUtils.isBlank(address)) {
			return new RSPE<Object>(-1, "详细地址不能为空");
		}

		CatDailyDrawResult drawResult = dailyDrawResultRepository.findByPidAndDrawId(pid, drawId.longValue());
		if (drawResult==null) {
			return new RSPE<Object>(-4, "中奖记录不存在！");
		}
		if (drawResult.getDrawStatus()>2) {
			return new RSPE<Object>(-5, "订单已发货,若修改信息,请问题反馈给客服！");
		}
		
		return new Callable<RSPE<Object>>() {
			@Override
			public RSPE<Object> call() throws Exception {
				CatDailyDrawAwardeeOrder order=catDevActService.receiveDailyDrawPrize(drawResult,recipientName,recipientPhone,area,address);;
				if (order == null) {
					return new RSPE<Object>(0, "填写失败，请稍后重试！");
				}
				return new RSPE<Object>(order);
			}
		};
	}
	
	@PostMapping("/daily/draw/order")
	@ApiOperation(value = "天天抽奖查询订单信息", position =10, notes = "天天抽奖查询订单信息", response = CatDailyDrawAwardeeOrderResp.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "rtype", value = "客户端", example = "0", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "vscode", value = "APP版本号", example = "1001", required = true, dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "drawId", value = "抽奖ID", example = "1111111111", dataType = "int", paramType = "form"),
			@ApiImplicitParam(name = "pid", value = "用户登录时的返回字段", example = "1111111111", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "uuid", value = "MD5(随机数)", example = "27b8f8538f84fa456f783e600c27dd18", required = true, dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "utoken", value = "用户登录时的返回字段", example = "1001", dataType = "String", paramType = "form"),
			@ApiImplicitParam(name = "token", value = "MD5(uuid_vscode_pid_rtype_time)", example = "1001", dataType = "String", paramType = "form") })
	@CheckingMD5(checkingStr = "uuid_vscode_pid_rtype", MD5 = "token")
	@CheckDevPermission
	public Object getDailyDrawOrderInfo(Integer rtype,String uuid,Integer vscode, Integer drawId,
			String pid,String utoken, String token) {
		if (StringUtils.isBlank(pid) || StringUtils.isBlank(utoken) || StringUtils.isBlank(token)) {
			return new RSPE<Object>(-2, "参数错误！");
		}
		if (drawId==null) {
			return new RSPE<Object>(-2, "抽奖ID为空！");
		}
		CatDailyDrawAwardeeOrder awardeeOrder = dailyDrawAwardeeOrderRepository.findByPidAndDrawId(pid, drawId.longValue());
		if (awardeeOrder==null) {
			return new RSPE<Object>(-4, "订单记录不存在！");
		}
		
		CatDailyDrawAwardeeOrderResp orderResp = new CatDailyDrawAwardeeOrderResp();
		BeanUtils.copyProperties(awardeeOrder, orderResp);	
		return new Callable<RSPE<CatDailyDrawAwardeeOrderResp>>() {
			@Override
			public RSPE<CatDailyDrawAwardeeOrderResp> call() throws Exception {
				CatDailyDrawDetailResp re = catDevActService.getDailyDrawDetail(pid,drawId);
				orderResp.setDrawDetail(re);
				if (re == null) {
					return new RSPE<CatDailyDrawAwardeeOrderResp>(-3, "查询订单信息失败！");
				}
				return new RSPE<CatDailyDrawAwardeeOrderResp>(orderResp);
			}
		};
	}
}
